<?php
/**
 * class App_Model_State
 *
 * @author kim
 */
class App_Model_State extends App_Model_Abstract
{
    // table name
    protected $_name = 'dine2_state';

    /**
     * list as id => name
     *
     * @return array
     */
     /*
    public function listAll()
    {
        $result = array();
        $db = $this->getTable()->getAdapter();
        $query = "SELECT `dine2_state`.`id`, `dine2_state`.`name` as state_name, `dine2_country`.`name` as country_name "
               . "FROM `dine2_state` LEFT JOIN `dine2_country` ON `dine2_state`.`country_id` = `dine2_country`.`id`";
        $rs = $db->fetchAll($query);
        foreach ($rs as $r) {
            $result[$r['country_name']][$r['id']] = $r['state_name'];
        }
        return $result;
    }
    */

    /**
     * list states as "id => name" by country id
     *
     * @return array
     */
    public function getStatesByCountryId($id)
    {
        $db = $this->getTable()->getAdapter();
        $query = "SELECT `id`, `name` FROM `dine2_state` WHERE `country_id` = '$id'";
        return $db->fetchPairs($query);
    }
}